import { Action, createReducer, on } from "@ngrx/store";
import * as keywordActions from "../actions/keyword.action";

export interface State {
  keyword: string;
}

export const initialState: State = {
  keyword: ""
};

const keywordReducer = createReducer(
  initialState,
  on(keywordActions.setKeyword, (state, { propKeyword }) => ({
    ...state,
    keyword: propKeyword
  })),
  on(keywordActions.cleanKeyword, state => ({
    ...state,
    keyword: ""
  }))
);

export function reducer(state: State | undefined, action: Action) {
  return keywordReducer(state, action);
}
